package ftl.games.piratas;

import org.anddev.andengine.engine.handler.physics.PhysicsHandler;
import org.anddev.andengine.entity.IEntity;
import org.anddev.andengine.entity.modifier.LoopEntityModifier;
import org.anddev.andengine.entity.modifier.PathModifier;
import org.anddev.andengine.entity.modifier.PathModifier.IPathModifierListener;
import org.anddev.andengine.entity.modifier.PathModifier.Path;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

public abstract class Inmueble extends AnimatedSprite {

	private final PhysicsHandler mPhysicsHandler;
	private int posPuerta = 0;
	private float []coordPuerta = new float[4];
	
	
	
	public Inmueble(float pX, float pY, float pTileWidth, float pTileHeight,TiledTextureRegion pTiledTextureRegion) {
		super(pX, pY, pTileWidth, pTileHeight, pTiledTextureRegion);
		this.mPhysicsHandler = new PhysicsHandler(this);
		this.Inicio();
		
	}

	public Inmueble(final float pX, final float pY, final TiledTextureRegion pTextureRegion) {
		super(pX, pY, pTextureRegion);
		this.mPhysicsHandler = new PhysicsHandler(this);
		this.Inicio();

	}
	public void Inicio ()
	{
		this.registerUpdateHandler(this.mPhysicsHandler);
	}
	
	public void setPosPuerta (String pPos)
	{
		this.setPosPuerta(Integer.parseInt(pPos));
	}
	public void setPosPuerta (int pPos)
	{
		this.posPuerta = pPos;
		this.setCoordenadasPuerta();
		this.Rotar();
	}
	public int getPosPuerta ()
	{
		return this.posPuerta;
	}
	
	private void setCoordenadasPuerta()
	{
		switch (this.posPuerta)
		{
			case 90:
				this.coordPuerta[0] = this.getX() - 32f;
				this.coordPuerta[1] = this.getX();
				this.coordPuerta[2] = this.getY();
				this.coordPuerta[3] = this.getY() + this.getHeight();
				break;
			
			case 180:
				this.coordPuerta[0] = this.getX();
				this.coordPuerta[1] = this.getX() + this.getWidth();
				this.coordPuerta[2] = this.getY() - 32f;
				this.coordPuerta[3] = this.getY();

				break;
				
			case 270:
				this.coordPuerta[0] = this.getX() + this.getWidth();
				this.coordPuerta[1] = this.coordPuerta[0] + 32f;
				this.coordPuerta[2] = this.getY();
				this.coordPuerta[3] = this.coordPuerta[2] + this.getHeight();				
				break;
				
			case 0:
				this.coordPuerta[0] = this.getX();
				this.coordPuerta[1] = this.coordPuerta[0] + this.getWidth();
				this.coordPuerta[2] = this.getY() + this.getHeight();
				this.coordPuerta[3] = this.coordPuerta[2] + 32f;				
				break;
		}
		
	}
	public float[] getCoordenadasPuerta()
	{
		return this.coordPuerta;
	}
	
	private void Rotar ()
	{
		this.setRotation(this.posPuerta);
	}
	
	public boolean EstaElCamionEnLaPuerta( Camion pCamion )
	{
		if (pCamion.getX() >= this.coordPuerta[0] && pCamion.getX() <= this.coordPuerta[1] && pCamion.getY() >= this.coordPuerta[2] && pCamion.getY() <= this.coordPuerta[3])
		{
			return true;
		}
		return false;
	}


		
	
}
